package com.tjsinfo.tjsoa.bylaws.bo;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.tjsinfo.tjsoa.Dao.IHibernateDao;
import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.bylaws.dao.IBylawsDao;
import com.tjsinfo.tjsoa.bylaws.vo.Bylaws;


public class BylawsBO implements IBylawsBO{

	private IBylawsDao bylawsDao;
	private IHibernateDao hibernateDao;
	private IQbcDao qbcDao;
	
	public IQbcDao getQbcDao() {
		return qbcDao;
	}

	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}

	public IHibernateDao getHibernateDao() {
		return hibernateDao;
	}

	public void setHibernateDao(IHibernateDao hibernateDao) {
		this.hibernateDao = hibernateDao;
	}

	public IBylawsDao getBylawsDao() {
		return bylawsDao;
	}

	public void setBylawsDao(IBylawsDao bylawsDao) {
		this.bylawsDao = bylawsDao;
	}
	
	public void save( Bylaws tjb){ 
		 hibernateDao.saveObject(tjb);
	}

	public void removeArticle(String articleId){ 
		bylawsDao.removeArticle(articleId);
	}

	public List findAll(){ 
		return bylawsDao.findAll();
	}

	public List findByProperty(String propertyName, String value){ 
		return bylawsDao.findByProperty(propertyName,value);
	}

	public List findByTwoProperty(String propertyName1, String value1,String propertyName2, String value2){ 
		return bylawsDao.findByTwoProperty(propertyName1,value1,propertyName2,value2);
	}

	public List findByThreeProperty(String propertyName1, String value1,String propertyName2, String value2, String propertyName3, String value3){ 
		return bylawsDao.findByThreeProperty(propertyName1,value1,propertyName2,value2,propertyName3,value3);
	}
	
	public List queryResult(String propertyName1, String value1,String propertyName2, String value2){ 
		return bylawsDao.queryResult(propertyName1,value1,propertyName2,value2);
	}
	
	public List findList(String value, String value1 ){ 
		return bylawsDao.findByProperty(value,value1);
	}
	
	public List findTopList(String value, String value1){
		return bylawsDao.findList(value, value1);
		
	}

	public List findByFlowId(Integer flowid) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(Bylaws.class);
		criteria.add(Restrictions.eq("flowid", flowid));
		return qbcDao.getCriteria(criteria);
		 
	}

	public Bylaws findById(String id) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(Bylaws.class);
		criteria.add(Restrictions.eq("id", id));
		List<Bylaws> list =  (List<Bylaws>)qbcDao.getCriteria(criteria); 
		return list.get(0);
	}

	public Boolean updateBylaws(Bylaws bylaws) {
		// TODO Auto-generated method stub
		try {
			hibernateDao.update(bylaws);
			return true;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
	}
	
	


 
}
